
import { data } from "./dataStore";

//为了能让Java获取到 数据必须绑定在全局变量window上
window.data = data;

//修改 Console
console._log = console.log;
console._error = console.error;
console.log = (message, optionalParams)=>{
  console._log(message, optionalParams);
  if(window.java && window.java.log){
    java.log(message);
  }
};
console.error = (message, optionalParams)=>{
  console._error(message, optionalParams);
  if(window.java && window.java.error){
    java.error(message);
  }
};

window.onerror = (event, source, filelen, columnNumber, error)=>{
  if(window.java && window.java.error){
    java.error(event + source + filelen + columnNumber + error);
  }
};

let emit = (name, message) => {
  if(window.java && window.java.message){
    java.emit(name, message);
  }
};

export {emit}